﻿package com.potocrewz.loaders
{
	
	import flash.net.URLLoader
	import flash.net.URLRequest
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.xml.XMLDocument;
	import flash.errors.*
	import flash.events.*
	public class LoadXML extends EventDispatcher
	{
		private var loader : URLLoader;
		public var mainXML : XML;
		public function LoadXML(pXML:String, pParam:String = "") {
			
			var Request = new URLRequest(pXML)
			
			if(pParam != ""){
				Request.data = new URLVariables (pParam);
				Request.method = URLRequestMethod.POST;
			}
			
			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(Request);
		}
		
		private function onComplete(evt:Event)
		{
			try
			{
				
				mainXML = new XML(loader.data);
				//mainXML.ignoreWhite = true;
				mainXML.ignoreWhitespace = true;
			
				dispatchEvent(new Event(Event.COMPLETE));
			} catch(e:Error)
			{
				trace("Error: " + e.message)
				return;
			}
		}
	}
}